using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Collections.Generic;
using ProtoBuf;

public enum Spell_Power_Type{
	Physical = 1,
	Electric,
	Thermal,
	Magnetic,
	Heal,
	Energizer
};

public enum Spell_Type{
	Damager = 1,
	Healer,
	Enchantment,
	Curse,
	Blessing
};

public enum Spell_Apply_Type{
	Npc_Aggressive=1,
	Npc_Friendly,
	Obj_Weapon,
	Ench_Weapon,
	Obj_Cloth,
	Use_Item,
	Charm
}


public class Base_Spell  {

	
	[ProtoMember(1)]	public string patch_Icon { get; set; }
	[ProtoMember(2)]	public string patch_Src_FX { get; set; }
	[ProtoMember(3)]	public string patch_Dst_FX { get; set; }
	[ProtoMember(4)]	public float Delay { get; set; }
	[ProtoMember(5)]	public string Name { get; set; }
	[ProtoMember(6)]	public string Description { get; set; }
	[ProtoMember(7)]	public Spell_Type Spell_Type { get; set; }
	[ProtoMember(8)]	public Spell_Apply_Type AppliedTo { get; set; }
	[ProtoMember(9)]	public float Speed { get; set; }
	[ProtoMember(10)]	public string patch_Sound_Cast { get; set; }
	[ProtoMember(11)]	public string patch_Sound_Hit { get; set; }
	[ProtoMember(12)]	public string patch_Hit_FX { get; set; }	
	[ProtoMember(13)]	public int Id { get; set; }	
	
	//private Texture Icon { get; set; }
	//public GameObject Src_FX { get; set; }
	//public GameObject Dst_FX { get; set; }
	private Vector3 Src_Point { get; set; }
	private Vector3 Dst_Point { get; set; }	
	
	void Spell_Cast()
	{
		
	}
	void Awake()
	{
		Src_Point = Vector3.zero;
		Dst_Point = Vector3.zero;
		Delay = 1.0f;
	}
	
	public void Save( FileStream sm )
	{
		using(MemoryStream ms = new MemoryStream()){
	   		Serializer.Serialize(ms, this);
			long psize = ms.Position;
			sm.Write(BitConverter.GetBytes(psize),0,4);
			ms.WriteTo(sm);
			Debug.Log("SSave - " + psize + "/" + sm.Position.ToString());

		}
	}
	
	public void Load( FileStream sm )
	{
		long psize = IOHelper.ReadLong(sm);
		Byte[] bf = new Byte[psize];
		sm.Read(bf,0,(int)psize);

		using(MemoryStream ms = new MemoryStream(bf)){
			Base_Spell tmp = Serializer.Deserialize<Base_Spell>(ms);

			patch_Icon = tmp.patch_Icon;
			patch_Src_FX = tmp.patch_Src_FX;
			patch_Dst_FX = tmp.patch_Dst_FX;
			Delay = tmp.Delay;
			Name = tmp.Name;
			Description = tmp.Description;
			Spell_Type = tmp.Spell_Type;
			AppliedTo = tmp.AppliedTo;
			Speed = tmp.Speed;
			Debug.Log("SLoad - " + psize.ToString()+ "/ "+ sm.Position.ToString() );
		}
	}
}
